<?php

use yii\db\Migration;

/**
 * Handles the creation of table `sms`.
 */
class m170717_074919_create_sms_table extends Migration
{
    /**
     * @inheritdoc
     */
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%sms}}', [
            'id' => $this->primaryKey()->comment('自增ID'),
            'mobile' => $this->string(11)->notNull()->comment('手机号'),
            'sms_code' => $this->integer(4)->notNull()->comment('手机验证码'),
            'type' => $this->smallInteger(2)->notNull()->defaultValue(1)->comment('类型:1注册2登录'),
            'created_at' => $this->integer()->notNull()->comment('创建时间')
        ], $tableOptions);
    }

    /**
     * @inheritdoc
     */
    public function down()
    {
        $this->dropTable('sms');
    }
}
